//
//  QMD5Hash.m
//  QoilPublic
//
//  Created by 杨凯 on 16/8/24.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QMD5Hash.h"

static NSString *s = @"sevalo_oil!@#$%^&*()";
@implementation QMD5Hash

+ (NSString *)md5String:(NSString *)str
{
    
    str = [NSString stringWithFormat:@"%@%@",str,s];
    const char *string = str.UTF8String;
    int length = (int)strlen(string);
    unsigned char bytes[CC_MD5_DIGEST_LENGTH];
    CC_MD5(string, length, bytes);
    return [QMD5Hash stringFromBytes:bytes length:CC_MD5_DIGEST_LENGTH];

}

+ (NSString *)stringFromBytes:(unsigned char *)bytes length:(int)length
{
    NSMutableString *mutableString = @"".mutableCopy;
    for (int i = 0; i < length; i++)
        [mutableString appendFormat:@"%02x", bytes[i]];
    return [NSString stringWithString:mutableString];
}


@end
